package com.tjsinfo.tjsoa.vote.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.vote.bo.ITVoteConformationBO;
import com.tjsinfo.tjsoa.vote.vo.TVoteConformation;

public class ConformationAddAction extends Action {
	private ITVoteConformationBO conformationBo;
	public void setConformationBo(ITVoteConformationBO conformationBo) {
		this.conformationBo = conformationBo;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			String headId = request.getParameter("headId");
			String parentId = request.getParameter("parentId");
			TVoteConformation vc = new TVoteConformation();
			vc.setParentId(parentId);
			vc.setHeadId(headId);
			vc.setName(request.getParameter("name"));
			if("0".equals(parentId)){
				vc.setRowNum(0);
				vc.setColumnNum(0);
			}else{
				TVoteConformation vcs = conformationBo.findById(parentId);
				int rowStatus = vcs.getRowNum();
				vcs.setRowNum(rowStatus+1);
				conformationBo.update(vcs);
			}
			vc.setOrderId(Integer.parseInt(request.getParameter("orderId")));
			conformationBo.save(vc);
			
			request.setAttribute("linkurl", "tjsinfo/tjsoa/vote/conformationList.do?headId="+headId+"@status="+request.getParameter("status")+"@parentId="+parentId+"");
			request.setAttribute("message", "vote.conformationAdd.message");
			
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
